//获取应用实例
const app = getApp();
var api = require('../../utils/api.js');
var util = require('../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    total: '',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.setData({
      code: options.code
    })
    this.getInfo()
  },

  //餐券信息
  getInfo: function() {
    var that = this;
    api.POST({
      url: app.globalData.base_url + 'Mealticket/getCodeInfo',
      params: {
        linkCode: that.data.code
      },
      success: function(res) {
        if (res.data.code == '') {
          that.setData({
            list: res.data.data.list,
            total: res.data.data.total
          })
        } else {
          wx.showModal({
            title: '提示',
						content: res.data.message,
						showCancel: false,
            success(res) {
							wx.switchTab({
								url: '/pages/business/business',
							})
            }
          })
        }
      }
    });
  },

  //核销
  verification: function(e) {
    var that = this;
    wx.showModal({
      title: '提示',
      content: '是否确认“核销”',
      success(res) {
        if (res.confirm) {
          api.POST({
            url: app.globalData.base_url + 'Mealticket/cancel',
            params: {
              linkCode: that.data.code
            },
            success: function(res) {
              if (res.data.code == '') {
                wx.redirectTo({
                  url: '/pages/mealTicketVerificationSuccess/mealTicketVerificationSuccess?code=' + that.data.code,
                })
              } else {
                wx.showModal({
                  title: '提示',
                  content: res.data.message,
                  showCancel: false,
                  success(res) {
										wx.switchTab({
											url: '/pages/business/business',
										})
									}
                })
                return;
              }
            }
          });
        }
      }
    })
  }
})